package smcms.scheduled.Task;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import smcms.commons.api.entity.result.CommonsResult;
import smcms.scheduled.entity.Permissions;
import smcms.scheduled.feign.ResourceFeign;
import smcms.scheduled.feign.SsoFeignService;
import smcms.scheduled.mapper.TaskMapper;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;

@Component
@Transactional
public class Permission {
    private Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private TaskMapper taskMapper;
    @Autowired
    private SsoFeignService ssoFeignService;
    @Autowired
    private ResourceFeign resourceFeign;
    @Autowired
    private CommonsResult commonsResult;

//    @Scheduled(cron = "0 43 18 * * ?")
//    public void execute() {
//        logger.info("调用权限存储过程更新用户权限！");
//        taskMapper.permissionTask();
//        HashMap<String, String> params = new HashMap<>();
//        params.put("username","zhihuiyun");
//        params.put("password","ccl.666.fba");
//        ssoFeignService.login(params);
//        CommonsResult ssoPermission = resourceFeign.getCurrentPermission();
//        List<Permissions> PermissionsData = (List<Permissions>) ssoPermission.getData();
//        taskMapper.insertUserPermission(PermissionsData);
//        logger.info("数据更新成功！");
//    }
    public CommonsResult syncPermission(){
        CommonsResult ssoPermission = resourceFeign.getCurrentPermission();
        List<Permissions> PermissionsData = (List<Permissions>) ssoPermission.getData();
        taskMapper.insertUserPermission(PermissionsData);
        return commonsResult.success("同步成功");
    }
}
